<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>图书管理系统</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="../../static/bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../../static/bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="../../static/bower_components/Ionicons/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../../static/dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. We have chosen the skin-blue for this starter
        page. However, you can choose any other skin. Make sure you
        apply the skin class to the body tag so the changes take effect. -->
  <link rel="stylesheet" href="../../static/dist/css/skins/skin-blue.min.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

  <!-- Google Font -->
  <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<!--
BODY TAG OPTIONS:
=================
Apply one or more of the following classes to get the
desired effect
|---------------------------------------------------------|
| SKINS         | skin-blue                               |
|               | skin-black                              |
|               | skin-purple                             |
|               | skin-yellow                             |
|               | skin-red                                |
|               | skin-green                              |
|---------------------------------------------------------|
|LAYOUT OPTIONS | fixed                                   |
|               | layout-boxed                            |
|               | layout-top-nav                          |
|               | sidebar-collapse                        |
|               | sidebar-mini                            |
|---------------------------------------------------------|
-->
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <!-- Main Header -->
  <jsp:include page="../common/header.jsp"/>

  <!-- Left side column. contains the logo and sidebar -->
  <jsp:include page="../common/sidebar.jsp"/>

  <!-- Content Wrapper. Contains page content -->

  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        图书管理系统
        <small>Library management system</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
        <li class="active">Here</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content container-fluid">
      <%--表格--%>
      
      <!--------------------------
        | Your Page Content Here |
        -------------------------->
        <div class="row">
          <div class="col-xs-12">
            <div class="box">
              <div class="box-header">
                <h3 class="box-title">图书列表</h3>

                <div class="box-tools">
                  <form action="/book/list" class="form-inline">
                    <div class="input-group input-group-sm" style="width: 250px;">
                      <input type="text" name="key" class="form-control pull-right" placeholder="关键字">

                      <div class="input-group-btn">
                        <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
                        <button style="margin-left: 10px" type="button" class="btn btn-success " data-toggle="modal" data-target="#myModal">新增</button>
                      </div>
                    </div>
                  </form>
                  <!-- Modal -->
                  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                    <div class="modal-dialog" role="document">
                      <div class="modal-content">
                        <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                          <h4 class="modal-title" id="myModalLabel">图书信息</h4>
                        </div>
                        <div class="modal-body">
                          <form id="myForm">
                            <input type="hidden" name="bookID" id="bookID">
                            <div class="form-group">
                              <label>图书名称</label>
                              <input type="text" class="form-control" id="Title" name="Title" placeholder="请输入">
                            </div>
                            <div class="form-group">
                              <label>作者</label>
                              <input type="text"  class="form-control" id="AuthorName" name="AuthorName" placeholder="请输入">
                            </div>
                            <div class="form-group">
                              <label>ISBN</label>
                              <input type="text"  class="form-control" id="ISBN" name="ISBN" placeholder="请输入">
                            </div>
                            <div class="form-group">
                              <label>出版社</label>
                              <input type="text"  class="form-control" id="Publisher" name="Publisher" placeholder="请输入">
                            </div>
                            <div class="form-group">
                              <label>出版日期</label>
                              <input type="date"  class="form-control" id="PublicationDate"  name="PublicationDate" placeholder="请输入">
                            </div>
                            <div class="form-group">
                              <label class="radio-inline">
                                <input type="radio" name="flag" id="flag1" value="0"><label>已被借阅</label>
                              </label>
                              <label class="radio-inline">
                                <input type="radio" name="flag" id="flag2" value="1" checked><label>未被借阅</label>
                              </label>
                            </div>
                          </form>
                        </div>
                        <div class="modal-footer">
                          <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                          <button type="button" onclick="submitBtn()" class="btn btn-primary">确定</button>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="modal fade" id="myModalStr" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                    <div class="modal-dialog" role="document">
                      <div class="modal-content">
                        <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                          <h4 class="modal-title" id="myModalLabelStr">图书信息</h4>
                        </div>
                        <div class="modal-body">
                          <form id="myFormStr">
                            <fieldset disabled>
                            <input type="hidden" name="bookID" id="bookIDStr">
                            <div class="form-group">
                              <label>图书名称</label>
                              <input type="text" class="form-control" id="TitleStr" name="Title" placeholder="请输入">
                            </div>
                            <div class="form-group">
                              <label>作者</label>
                              <input type="text"  class="form-control" id="AuthorNameStr" name="AuthorName" placeholder="请输入">
                            </div>
                            <div class="form-group">
                              <label>ISBN</label>
                              <input type="text"  class="form-control" id="ISBNStr" name="ISBN" placeholder="请输入">
                            </div>
                            <div class="form-group">
                              <label>出版社</label>
                              <input type="text"  class="form-control" id="PublisherStr" name="Publisher" placeholder="请输入">
                            </div>
                            <div class="form-group">
                              <label>出版日期</label>
                              <input type="date"  class="form-control" id="PublicationDateStr"  name="PublicationDate" placeholder="请输入">
                            </div>
                            <div class="form-group">
                              <label class="radio-inline">
                                <input type="radio" name="flag" id="flag1Str" value="0"><label>已被借阅</label>
                              </label>
                              <label class="radio-inline">
                                <input type="radio" name="flag" id="flag2Str" value="1" checked><label>未被借阅</label>
                              </label>
                            </div>
                              </fieldset>
                          </form>
                        </div>
                        <div class="modal-footer">
                          <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <!-- /.box-header -->
              <div class="box-body table-responsive no-padding">
                <table class="table table-hover">
                  <tr>
                    <th>图书序号</th>
                    <th>书名</th>
                    <th>作者</th>
<%--                    <th>类型</th>--%>
                    <th>ISBN</th>
                    <th>出版社</th>
                    <th>出版日期</th>
                    <th>借阅状态</th>
                    <th>操作栏</th>
<%--                    <th>创建时间</th>--%>
                  </tr>
                  <c:forEach var="b" items="${PageInfo.records}" varStatus="BookID">
                    <tr>
                      <td>${BookID.count}</td>
                      <td>${b.title}</td>
                      <td>${b.authorName}</td>
<%--                      <td>${b.CategoryName}</td>--%>
                      <td>${b.iSBN}</td>
                      <td>${b.publisher}</td>
                      <td>${b.publicationDate}</td>
                      <td>
                        <c:if test="${b.flag eq 1 }">
                          <span class="label label-success">未被借阅</span>
                        </c:if>
                        <c:if test="${b.flag eq 0}">
                          <span class="label label-danger">已被借阅</span>
                        </c:if>
                      </td>
                      <td><button type="button" onclick="detilBtn('${b.bookID}')" class="btn btn-primary btn-sm">详情</button></td>
                      <td>
                        <button type="button" onclick="editBtn('${b.bookID}')" class="btn btn-info btn-sm">编辑</button>
                      </td>
                      <td><button type="button" onclick="delBtn('${b.bookID}')" class="btn btn-danger btn-sm">删除</button></td>
<%--                      <td>${b.createTime}</td>--%>
                    </tr>
                  </c:forEach>
                </table>
              </div>
              <!-- /.box-body -->
            </div>
            <!-- /.box -->
          </div>
          <%--分页--%>
          <div class="box-footer clearfix">
            <ul class="pagination pagination-sm no-margin pull-right">
              <li><a href="../../book/list?pageNo=1">首页</a></li>
              <li><a href="../../book/list?pageNo=${PageInfo.pre}">&laquo;</a></li>
              <li><a href="#">${PageInfo.current}/${PageInfo.totalPage}</a></li>
              <li><a href="../../book/list?pageNo=${PageInfo.next}">&raquo;</a></li>
              <li><a href="../../book/list?pageNo=${PageInfo.totalPage}">尾页</a></li>
            </ul>
            <form>
              跳转到<input type="number" name="pageNo" min="1"/>页
              <input type="submit" value="go">
            </form>
          </div>

        </div>
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <!-- Main Footer -->
  <jsp:include page="../common/footer.jsp"/>


  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Create the tabs -->
    <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
      <li class="active"><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
      <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
    </ul>
    <!-- Tab panes -->
    <div class="tab-content">
      <!-- Home tab content -->
      <div class="tab-pane active" id="control-sidebar-home-tab">
        <h3 class="control-sidebar-heading">Recent Activity</h3>
        <ul class="control-sidebar-menu">
          <li>
            <a href="javascript:;">
              <i class="menu-icon fa fa-birthday-cake bg-red"></i>

              <div class="menu-info">
                <h4 class="control-sidebar-subheading">Langdon's Birthday</h4>

                <p>Will be 23 on April 24th</p>
              </div>
            </a>
          </li>
        </ul>
        <!-- /.control-sidebar-menu -->

        <h3 class="control-sidebar-heading">Tasks Progress</h3>
        <ul class="control-sidebar-menu">
          <li>
            <a href="javascript:;">
              <h4 class="control-sidebar-subheading">
                Custom Template Design
                <span class="pull-right-container">
                    <span class="label label-danger pull-right">70%</span>
                  </span>
              </h4>

              <div class="progress progress-xxs">
                <div class="progress-bar progress-bar-danger" style="width: 70%"></div>
              </div>
            </a>
          </li>
        </ul>
        <!-- /.control-sidebar-menu -->

      </div>
      <!-- /.tab-pane -->
      <!-- Stats tab content -->
      <div class="tab-pane" id="control-sidebar-stats-tab">Stats Tab Content</div>
      <!-- /.tab-pane -->
      <!-- Settings tab content -->
      <div class="tab-pane" id="control-sidebar-settings-tab">
        <form method="post">
          <h3 class="control-sidebar-heading">General Settings</h3>

          <div class="form-group">
            <label class="control-sidebar-subheading">
              Report panel usage
              <input type="checkbox" class="pull-right" checked>
            </label>

            <p>
              Some information about this general settings option
            </p>
          </div>
          <!-- /.form-group -->
        </form>
      </div>
      <!-- /.tab-pane -->
    </div>
  </aside>
  <!-- /.control-sidebar -->
  <!-- Add the sidebar's background. This div must be placed
  immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->
<!-- Modal -->
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-sm" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="del">删除操作</h4>
      </div>
      <div class="modal-body">
        删除操作不可逆，请确定是否删除？
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" onclick="deleteBtn()" class="btn btn-primary">确定</button>
      </div>
    </div>
  </div>
</div>
<!-- REQUIRED JS SCRIPTS -->

<!-- jQuery 3 -->
<script src="../../static/bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="../../static/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- AdminLTE App -->
<script src="../../static/dist/js/adminlte.min.js"></script>

<!-- Optionally, you can add Slimscroll and FastClick plugins.
     Both of these plugins are recommended to enhance the
     user experience. -->

//增加
<script>
  function submitBtn() {
      var data = $('#myForm').serialize();
      console.log(data);

      //发送请求
      $.ajax({
        //设置请求类型
        type: 'get',
        //请求路径
        url: '/book/insert',
        //参数
        data: data,
        //成功响应
        success:function (res) {
          console.log(res)

          //关闭模态框
          $('#myModal').modal('hide');
          //刷新
          window.location.href='/book/list';
        },
      })
  }

  //编辑事件
  function editBtn(bookID) {
    //通过bookID获取信息
    $.ajax({
      type: 'get',
      url: '/book/getOne',
      data:'bookID=' + bookID,
      success:function (res) {
        console.log(res)
        //回显
        $("#bookID").val(res.bookID);
        $("#Title").val(res.title);
        $("#AuthorName").val(res.authorName);
        $("#ISBN").val(res.iSBN);
        $("#Publisher").val(res.publisher);
        $("#PublicationDate").val(res.publicationDatestr);
        res.flag? $("#flag2").prop("checked", "checked"): $("#flag1").prop("checked", "checked");

        $('#myModal').modal('show');
      }
    })
  }

  function detilBtn(bookID) {
    $.ajax({
      type: 'get',
      url: '/book/getOne',
      data:'bookID=' + bookID,
      success:function (res) {
        console.log(res)
        //回显
        $("bookID").val(res.bookID);
        $("#TitleStr").val(res.title);
        $("#AuthorNameStr").val(res.authorName);
        $("#ISBNStr").val(res.iSBN);
        $("#PublisherStr").val(res.publisher);
        $("#PublicationDateStr").val(res.publicationDatestr);
        res.flag? $("#flag2Str").prop("checked", "checked"): $("#flag1Str").prop("checked", "checked");

        $('#myModalStr').modal('show');
      }
    })
  }
  var id;
  function delBtn(bookID) {
    id= bookID;
    $('#delModal').modal('show');
  }

  function deleteBtn() {
    $.ajax({
      type: 'get',
      url: '/book/delete',
      data:'bookID=' + id,
      success:function (res) {
        console.log(res)
        $('#delModal').modal('hide');
        window.location.href='/book/list';
      }
    })
  }
</script>
</body>
</html>
